package cn.fsd.controller;

import cn.fsd.exception.AppException;
import cn.fsd.exception.SubStationExceptionCodeMsg;
import cn.fsd.query.substation.CourierQuery;
import cn.fsd.service.impl.CourierServiceImpl;
import cn.fsd.vo.ResultBean;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/courier")
public class CourierController {

  @Autowired
  CourierServiceImpl courierService;

  @PostMapping("/availableCourier")
  @ApiOperation(value = "查询所有可以分配任务的配送员")
  public ResultBean getAvailableCourier(@RequestBody CourierQuery query){
    if(StringUtils.isEmpty(query.getStation_id())){
      throw new AppException(SubStationExceptionCodeMsg.STATION_ID_EMPTY);
    }
    return ResultBean.success(courierService.getAvailableCouriers(query));
  }
}
